import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    tasklist:[],
  },
  getters: {
    unFinishCount(state){
      var arr = state.tasklist.filter((item)=>{
        return item.status==false;
      })
      return arr.length;
    }
  },
  mutations: {
    addTask(state,payload){
      var obj={id: state.tasklist.length+1,name:payload,status:false};
      state.tasklist.push(obj);
    },
    changeStatus(state,payload){
      var fi=state.tasklist.find((item)=>{
        return item.id==payload.id;
      });
      if(fi){
        fi.status=!fi.status;
      }
    }
  },
  actions: {
  },
  modules: {
  }
})
